/* $Id: ApplicationComponentListener.java 40 2009-12-24 14:58:58Z aaron.day $ */
package org.crazydays.gameplan.swing;


import java.awt.Component;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;

import org.crazydays.gameplan.Application;
import org.crazydays.gameplan.Preferences;

/**
 * ApplicationComponentListener
 */
public class ApplicationComponentListener
    implements ComponentListener
{
    /** preferences */
    protected Preferences preferences;

    /**
     * ApplicationComponentListener constructor.
     * 
     * @param preferences
     */
    public ApplicationComponentListener(Preferences preferences)
    {
        this.preferences = preferences;
    }

    /**
     * Application shown.
     * 
     * @param event Event
     * @see ComponentListener#componentShown(ComponentEvent)
     */
    @Override
    public void componentShown(ComponentEvent event)
    {
    }

    /**
     * Application hidden.
     * 
     * @param event Event
     * @see ComponentListener#componentHidden(ComponentEvent)
     */
    @Override
    public void componentHidden(ComponentEvent event)
    {
    }

    /**
     * Application moved.
     * 
     * @param event Event
     * @see ComponentListener#componentMoved(ComponentEvent)
     */
    @Override
    public void componentMoved(ComponentEvent event)
    {
        int x = ((Component) event.getSource()).getX();
        int y = ((Component) event.getSource()).getY();

        preferences.setProperty(Application.APPLICATION_X, x);
        preferences.setProperty(Application.APPLICATION_Y, y);
    }

    /**
     * Application resized.
     * 
     * @param event Event
     * @see ComponentListener#componentResized(ComponentEvent)
     */
    @Override
    public void componentResized(ComponentEvent event)
    {
        int width = ((Component) event.getSource()).getWidth();
        int height = ((Component) event.getSource()).getHeight();

        preferences.setProperty(Application.APPLICATION_WIDTH, width);
        preferences.setProperty(Application.APPLICATION_HEIGHT, height);
    }
}
